/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.pizzaria.view;

import br.com.pizzaria.util.Global;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.AbstractAction;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.KeyStroke;
import javax.swing.Timer;

/**
 *
 * @author Jaime
 */
public class MenuEmpresa extends javax.swing.JInternalFrame {

    FuncionarioView funcionarioV;

    UsuarioView usuarioV;
    EmpresaView empresaV;
    DefinirModuloView moduloV;
    ModuloView moduloV2;
    CargoFuncaoView cargoV;

    /**
     * Creates new form MenuProdução
     */
    public MenuEmpresa() {
        initComponents();
        Timer time = new Timer(1000, ativar);
        time.start();

        btnFuncionario.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.CTRL_DOWN_MASK), "evento");
        btnFuncionario.getActionMap().put("evento", new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                btnFuncionarioActionPerformed(e);
            }

        });

        btnEmpresa.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_2, InputEvent.CTRL_DOWN_MASK), "evento");
        btnEmpresa.getActionMap().put("evento", new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                btnEmpresaActionPerformed(e);
            }

        });

        btnUsuario.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_3, InputEvent.CTRL_DOWN_MASK), "evento");
        btnUsuario.getActionMap().put("evento", new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                btnUsuarioActionPerformed(e);
            }

        });
        btnModulo.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_4, InputEvent.CTRL_DOWN_MASK), "evento");
        btnModulo.getActionMap().put("evento", new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                btnModuloActionPerformed(e);
            }

        });
        btnFuncao.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_5, InputEvent.CTRL_DOWN_MASK), "evento");
        btnFuncao.getActionMap().put("evento", new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                btnFuncaoActionPerformed(e);
            }

        });
         btnFuncao1.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_6, InputEvent.CTRL_DOWN_MASK), "evento");
        btnFuncao1.getActionMap().put("evento", new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {
                btnFuncao1ActionPerformed(e);
            }

        });

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnFuncionario = new javax.swing.JButton();
        btnUsuario = new javax.swing.JButton();
        btnFuncao = new javax.swing.JButton();
        btnModulo = new javax.swing.JButton();
        btnEmpresa = new javax.swing.JButton();
        btnFuncao1 = new javax.swing.JButton();

        setTitle("Menu Empresa");
        setPreferredSize(new java.awt.Dimension(308, 477));

        btnFuncionario.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        btnFuncionario.setForeground(new java.awt.Color(0, 51, 255));
        btnFuncionario.setText("<html>Funcionário <font size='2' style='color:black'> Crtl-1 </font>");
        btnFuncionario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFuncionarioActionPerformed(evt);
            }
        });

        btnUsuario.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        btnUsuario.setForeground(new java.awt.Color(0, 51, 255));
        btnUsuario.setText("<html>Usuário <font size='2' style='color:black'> Crtl-3 </font>");
        btnUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUsuarioActionPerformed(evt);
            }
        });

        btnFuncao.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        btnFuncao.setForeground(new java.awt.Color(0, 51, 255));
        btnFuncao.setText("<html> Função <font size='2' style='color:black'> Crtl-5 </font>");
        btnFuncao.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFuncaoActionPerformed(evt);
            }
        });

        btnModulo.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        btnModulo.setForeground(new java.awt.Color(0, 51, 255));
        btnModulo.setText("<html>Módulo <font size='2' style='color:black'> Crtl-4 </font>");
        btnModulo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnModuloActionPerformed(evt);
            }
        });

        btnEmpresa.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        btnEmpresa.setForeground(new java.awt.Color(0, 51, 255));
        btnEmpresa.setText("<html>Empresa <font size='2' style='color:black'> Crtl-2 </font>");
        btnEmpresa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEmpresaActionPerformed(evt);
            }
        });

        btnFuncao1.setFont(new java.awt.Font("Arial", 1, 18)); // NOI18N
        btnFuncao1.setForeground(new java.awt.Color(0, 51, 255));
        btnFuncao1.setText("<html>Logout<font size='2' style='color:black'> Crtl-6 </font>");
        btnFuncao1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnFuncao1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnFuncionario, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnUsuario, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnModulo, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnFuncao, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE)
                    .addComponent(btnEmpresa, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(btnFuncao1, javax.swing.GroupLayout.DEFAULT_SIZE, 272, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnFuncionario, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnModulo, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnFuncao, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnFuncao1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnFuncionarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFuncionarioActionPerformed
        if (funcionarioV == null || !funcionarioV.isShowing()) {
            funcionarioV = new FuncionarioView();
            Global.principal.Desktop.add(funcionarioV);
            centralizaForm(funcionarioV);
            funcionarioV.setVisible(true);
        }
    }//GEN-LAST:event_btnFuncionarioActionPerformed

    private void btnUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUsuarioActionPerformed
        // TODO add your handling code here:
        if (usuarioV == null || !usuarioV.isShowing()) {
            usuarioV = new UsuarioView();
            Global.principal.Desktop.add(usuarioV);
            centralizaForm(usuarioV);
            usuarioV.setVisible(true);
        }
    }//GEN-LAST:event_btnUsuarioActionPerformed

    private void btnFuncaoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFuncaoActionPerformed
        // TODO add your handling code here:
        if (cargoV == null || !cargoV.isShowing()) {
            cargoV = new CargoFuncaoView();
            Global.principal.Desktop.add(cargoV);
            centralizaForm(cargoV);
            cargoV.setVisible(true);
        }
    }//GEN-LAST:event_btnFuncaoActionPerformed

    private void btnModuloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnModuloActionPerformed
        // TODO add your handling code here:
        if (moduloV == null || !moduloV.isShowing()) {
            moduloV = new DefinirModuloView();
            Global.principal.Desktop.add(moduloV);
            centralizaForm(moduloV);
            moduloV.setVisible(true);
        }
    }//GEN-LAST:event_btnModuloActionPerformed

    private void btnEmpresaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEmpresaActionPerformed
        if (empresaV == null || !empresaV.isShowing()) {
            empresaV = new EmpresaView();
            Global.principal.Desktop.add(empresaV);
            centralizaForm(empresaV);
            empresaV.setVisible(true);
        }
// TODO add your handling code here:
    }//GEN-LAST:event_btnEmpresaActionPerformed

    private void btnFuncao1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFuncao1ActionPerformed

        // TODO add your handling code here:
        this.dispose();
//        PrincipalView janela = new PrincipalView();
       Global.principal.habiltaMenu(false);
//        janela.setVisible(true);
//        Global.principal = janela;
        LoginView login = new LoginView();
        login.setVisible(true);
        centralizaForm(login);
        Global.principal.Desktop.add(login);
//        carregaLogin();


    }//GEN-LAST:event_btnFuncao1ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEmpresa;
    private javax.swing.JButton btnFuncao;
    private javax.swing.JButton btnFuncao1;
    private javax.swing.JButton btnFuncionario;
    private javax.swing.JButton btnModulo;
    private javax.swing.JButton btnUsuario;
    // End of variables declaration//GEN-END:variables
    ActionListener ativar = (new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            centralizarComponente();
        }

    });

    public final void centralizarComponente() {
        int x = Global.principal.getLocation().x;
        int y = Global.principal.getLocation().y;

        Dimension ds = Global.principal.getSize();
        Dimension dw = getSize();
        setLocation((0), (0));
    }

    private void centralizaForm(JInternalFrame frame) {
        Dimension desktopSize = Global.principal.Desktop.getSize();
        Dimension jInternalFrameSize = frame.getSize();
        frame.setLocation((desktopSize.width - jInternalFrameSize.width) / 2,
                (desktopSize.height - jInternalFrameSize.height) / 2);
    }

    public void carregaLogin() {

    }
}
